/**
 * 安卓白金英雄坛制作组 <br>
 * 文件名：PracticeMenuScreen.java <br>
 * 创建时间：2013-7-22 上午11:33:22 <br>
 * 所属项目：GmudEX <br>
 * @author 12548 <br>
 */
package lostland.gmud.exv2.ui;

import com.orhanobut.logger.Logger;

import lostland.gmud.exv2.Game;
import lostland.gmud.exv2.Gmud;
import lostland.gmud.exv2.MapScreen;
import lostland.gmud.exv2.data.Skill;
import lostland.gmud.exv2.ui.core.GmudWindow;
import lostland.gmud.exv2.ui.core.MenuScreen;

/**
 * 类名：PracticeMenuScreen <br>
 * 说明：系统菜单
 *
 * @author 12548
 */
public class PracticeMenuScreen extends MenuScreen {


	/**
	 * @param instance
	 */
	public PracticeMenuScreen() {
		super(getWindows());
		dummyBorder = new PracticeMenuBorder();
	}


	/* （非 Javadoc）
	 * @see lostland.gmud.exv2.ui.MenuScreen#onClick(int)
	 */
	@Override
	protected void onClick(int index) {
		if (Gmud.mc.skillsckd[3] == -1)
			new NotificationScreen("请先选择你要用的内功心法！").pushToGame();
		else switch (((PracticeMenuButton) buttons[index]).item) {
			case 0:
				if (Gmud.mc.isHungry()) {
					new NotificationScreen("你浑身使不出一点力气，还是先吃饱了再练功吧！").pushToGame();
					break;
				}
				if (Gmud.mc.skills[Gmud.mc.skillsckd[0]] > Gmud.mc.skills[Gmud.skill[Gmud.mc.skillsckd[0]].getBasicSkill().id])
					new NotificationScreen("你的功夫很难再有所提高了，还是向师傅请教下吧").pushToGame();
				else if (!Gmud.mc.expcanlearn(Gmud.mc.skills[Gmud.mc.skillsckd[0]] + 1))
					new NotificationScreen("你的武学经验不足，无法领会更深的功夫").pushToGame();
				else if (Gmud.mc.maxfp < Gmud.mc.skills[Gmud.mc.skillsckd[0]] + 1)
					new NotificationScreen("你的内力修为不足，要勤修内功！").pushToGame();
				else if (Gmud.mc.haveTalent(1003)) // 天赋效果1003
				{
					Gmud.mc.skills[Gmud.mc.skillsckd[0]] = Gmud.mc.skills[Gmud.skill[Gmud.mc.skillsckd[0]].getBasicSkill().id] + 1;
					new NotificationScreen("【信手拈来】你的" + Gmud.skill[Gmud.mc.skillsckd[0]].name + "上升到了" + Gmud.mc.skills[Gmud.mc.skillsckd[0]] + "级").pushToGame();
				} else
					new PracticingScreen(Gmud.mc.skillsckd[0]).pushToGame();
				break;
			case 1:
				if (Gmud.mc.skills[Gmud.mc.skillsckd[1]] > Gmud.mc.skills[Gmud.skill[Gmud.mc.skillsckd[1]].getBasicSkill().id])
					new NotificationScreen("你的功夫很难再有所提高了，还是向师傅请教下吧").pushToGame();
				else if (Gmud.mc.skillsckd[1] <= 0 || Gmud.skill[Skill.eqpbias2[Gmud.mc.getAttackItem().getSubkind()]].subkind != Gmud.skill[Gmud.mc.skillsckd[1]].subkind)
					new NotificationScreen("趁手的兵器都没有一把，瞎比划什么？").pushToGame();
				else if (!Gmud.mc.expcanlearn(Gmud.mc.skills[Gmud.mc.skillsckd[1]] + 1))
					new NotificationScreen("你的武学经验不足，无法领会更深的功夫").pushToGame();
				else if (Gmud.mc.maxfp < Gmud.mc.skills[Gmud.mc.skillsckd[1]] + 1)
					new NotificationScreen("你的内力修为不足，要勤修内功！").pushToGame();
				else if (Gmud.mc.haveTalent(1003)) // 天赋效果1003
				{
					Gmud.mc.skills[Gmud.mc.skillsckd[1]] = Gmud.mc.skills[Gmud.skill[Gmud.mc.skillsckd[1]].getBasicSkill().id] + 1;
					new NotificationScreen("【信手拈来】你的" + Gmud.skill[Gmud.mc.skillsckd[1]].name + "上升到了" + Gmud.mc.skills[Gmud.mc.skillsckd[1]] + "级").pushToGame();
				} else
					new PracticingScreen(Gmud.mc.skillsckd[1]).pushToGame();
				break;
			case 2:
				boolean d1, d2, d3;

				d1 = Gmud.mc.skills[Gmud.mc.skillsckd[2]] > Gmud.mc.skills[Gmud.skill[Gmud.mc.skillsckd[2]].getBasicSkill().id];
				Logger.w("d1");
				d2 = !Gmud.mc.expcanlearn(Gmud.mc.skills[Gmud.mc.skillsckd[2]] + 1);
				Logger.w("d2");
				d3 = Gmud.mc.maxfp < Gmud.mc.skills[Gmud.mc.skillsckd[2]] + 1;
				Logger.w("d3");
				if (d1)
					new NotificationScreen("你的功夫很难再有所提高了，还是向师傅请教下吧").pushToGame();
				else if (d2)
					new NotificationScreen("你的武学经验不足，无法领会更深的功夫").pushToGame();
				else if (d3)
					new NotificationScreen("你的内力修为不足，要勤修内功！").pushToGame();
				else if (Gmud.mc.haveTalent(1003)) // 天赋效果1003
				{
					Gmud.mc.skills[Gmud.mc.skillsckd[2]] = Gmud.mc.skills[Gmud.skill[Gmud.mc.skillsckd[2]].getBasicSkill().id] + 1;
					new NotificationScreen("【信手拈来】你的" + Gmud.skill[Gmud.mc.skillsckd[2]].name + "上升到了" + Gmud.mc.skills[Gmud.mc.skillsckd[2]] + "级").pushToGame();
				} else
					new PracticingScreen(Gmud.mc.skillsckd[2]).pushToGame();
				break;
		}
	}


	static GmudWindow[] getWindows() {
		int n = 0, i = 0;
		if (Gmud.mc.skillsckd[0] > 10) n++;
		if (Gmud.mc.skillsckd[1] > 10) n++;
		if (Gmud.mc.skillsckd[2] > 10) n++;
		PracticeMenuButton[] tw = new PracticeMenuButton[n];

		if (n == 0) {
			Game.getInstance().popScreen();
			return tw;
		}

		if (Gmud.mc.skillsckd[0] > 10) tw[i] = new PracticeMenuButton(i++, 0);
		if (Gmud.mc.skillsckd[1] > 10) tw[i] = new PracticeMenuButton(i++, 1);
		if (Gmud.mc.skillsckd[2] > 10) tw[i] = new PracticeMenuButton(i++, 2);

		return tw;
	}

	/* （非 Javadoc）
	 * @see lostland.gmud.exv2.ui.MenuScreen#onCancel()
	 */
	@Override
	public void onCancel() {
		getGame().popScreen();
	}


	/* （非 Javadoc）
	 * @see lostland.gmud.exv2.ui.core.ButtonControlledScreen#show()
	 */
	@Override
	protected void show() {
		if (buttons.length == 0) {
			getGame().popScreen();
			return;
		}

		MapScreen.getInstance().present(-1);
		dummyBorder.draw();
		for (GmudWindow i : buttons) {
			i.draw();
		}
	}
}
